<?php
    /**
     * Created by PhpStorm.
     * User: Feixiang
     * Date: 2017/8/7
     * Time: 11:06
     */
    namespace Admin\Controller;
    use Think\Controller;
    
    
    class LoginController extends Controller {
    
        /**
         *
         */
        public function index(){
//            echo getMd5Password('123456');die;
//            dump(session());die;
            if (session('adminUser')){
//                $this->redirect('/index.php?m=admin&c=index');
                $this->redirect('Admin/Index/index');
            }
            
            $this->display();
            
        }
        public  function check(){
//            print_r($_POST);
//            前端判断，后端也要做强校验，为安全考虑
            $username = $_POST['username'];
            $password = $_POST['password'];
            if (!trim($username)){
                return show(0,'用户名不为空');
            
            }
            if (!trim($password)){
                return show(0,'密码不为空');
        
            }
            $ret = D('Admin')->getAdminByUsername($username);
//            dump($ret['password']);
//            dump('|');
//            dump(getMd5Password($password));die;
            if (!$ret){
                return show(0,'该用户不存在');
            }
          if ($ret['password'] != getMd5Password($password)){
                return show(0,'密码错误');
            }
            session('adminUser',$ret);
            return show(1,'登录成功');
        }
//        退出登录
        public function loginout(){
            session('adminUser',null);
//            a=index 是方法
//            $this->redirect('../index.php?m=admin&c=login&a=index');
            $this->redirect('Admin/Login/index');
        }
        
    }